package com.lay.layutls.mapstruct;

import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

@Mapper
public interface CarMapper {

    CarMapper INSTANCE = Mappers.getMapper(CarMapper.class);

    @Mapping(source = "numberOfSeats", target = "seatCount")
    @Mapping(target = "type", constant = "default type")
    @Mapping(source = "brand", target = "carBrand")
    @Mapping(source = "birthday", ignore = true, target = "date", dateFormat = "yyyy-MM-dd")
    @Mapping(source = "price", target = "price", numberFormat = "0.00")
    CarDto carToCarDto(Car car);

    @Mappings(
            {
                    @Mapping(source = "numberOfSeats", target = "seatCount"),
                    @Mapping(target = "type", constant = "default type"),
                    @Mapping(source = "brand.brandName", target = "carBrand.carBrand")
            }
    )
    CarDto carToCarDto2(Car car);

 /*    @Mappings({
            @Mapping(source = "brandName", target = "carBrand")
    })
    CarBrand brand2CarBrand(Brand brand); */


    @Mappings({
            @Mapping(source = "brandName", target = "carBrand"),
            @Mapping(source = "brandCode", target = "code"),
    })
    CarBrand brand2CarBrandV2(Brand brand);


    @AfterMapping
    default void carToCarDtoAfterMapping(Car car, @MappingTarget CarDto carDto) {
        carDto.setExtral("额外的参数");
    }
}